package accounts;
import tester.cobertura.Instrument;

/**
 * @author Adam Blackwell
 */
// to represent a checking account in a bank
@Instrument 
public class Checking extends Account {

	public int minimum; // The minimum amount a customer is allowed to have

	/**
	 * @param num
	 * @param name
	 * @param balance
	 * @param owner
	 * @param minimum
	 */
	public Checking(int num, String name, int balance, String owner, int minimum) {
		super(num, name, balance, owner);
		this.minimum = minimum;
		// TODO Auto-generated constructor stub
	}

	/*
	 * TEMPLATE: FIELDS: 
	 * ... num ...     -- int 
	 * ... name ...    -- String 
	 * ... balance ... -- int 
	 * ... owner ...   -- String 
	 * ... minimum ... -- int
	 * 
	 * METHODS: 
	 * ... deposit(int amt) ...  -- Account 
	 * ... withdraw(int amt) ... -- Account
	 */

	// produce an updated account after depositing the given amount
	@Override
	public Account deposit(int amt) {
		return new Checking(this.num, this.name, this.balance + amt, this.owner,
				this.minimum);
	}

	// produce an updated account after withdrawing the given amount
	@Override
	public Account withdraw(int amt) {
		if (this.balance - this.minimum >= amt) {
			return new Checking(this.num, this.name, this.balance - amt, this.owner,
					this.minimum);
		} else {
			throw new RuntimeException(
					"Insufficient Funds in the checking account.");
		}
	}
}
